﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class CardCenter_ChargetoAccount : System.Web.UI.Page
{
    private WebUtility util;
    UserBean bllUser = new UserBean();
    BLL.TransCardPoints2UserAccount trans = new TransCardPoints2UserAccount();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Cards"] == null)
        {
           Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }

    }

    
    protected void ImgBtnTrans_Click(object sender, ImageClickEventArgs e)
    {
        string accountName = this.txt_AccountNO.Text;
        util = new WebUtility();
        if (String.IsNullOrEmpty(accountName))
        {
            util.AlertMsg("输入不能为空!");
        }
        else {//--------------------
            bool flag = bllUser.IsExistsUserInfo(accountName);
            if (flag == false)
            {
                util.AlertMsg("该帐户不存在，请重新输入！");
                this.txt_AccountNO.Text = string.Empty;
                return;
            }
            else {
                Cards[] cards =  (Cards[])Session["Cards"];
                if(cards != null && cards.Length > 0){
                    int _flag = 0;
                    int k = 0;
                    for (int i = 0; i < cards.Length;i++ )
                    {
                        string cardNo = cards[i].CardSeriaNumber;
                        string password = cards[i].CardPassword;
                        _flag = trans.transCardPoints(cardNo, password, accountName);
                        if(_flag == 1){
                            k++;
                        }
                    }
                    //----------------
                    if (k == cards.Length)
                    {
                        util.AlertMsg("给帐户:" + accountName + "充值成功!");
                        Session["Cards"] = null;
                    }
                    else {
                        util.AlertMsg("给帐户:" + accountName + "充值失败!");
                        Session["Cards"] = null;
                    }
                }
            }
        }//----------------------
    }

    //-----------------------------------------------------------------------------
}
